package br.com.hotel.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.hotel.command.CommandAdministrador;

/**
 * Servlet implementation class for Servlet: ServletController
 *
 */
 public class ServletController extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ServletController() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processarRequisicao(request, response);
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processarRequisicao(request, response);
	}
	

	
	private void processarRequisicao(HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException {
		
			if(request.getParameter("cmd").trim().equalsIgnoreCase("entrar")){
				CommandAdministrador ca = new CommandAdministrador();
				ca.entrarSistema(request, response);
			}else if(request.getParameter("cmd").trim().equalsIgnoreCase("cadastrarAdm")){
				CommandAdministrador ca = new CommandAdministrador();
				ca.cadastrarAdministrador(request, response);
			}else if(request.getParameter("cmd").trim().equalsIgnoreCase("sair")){
				CommandAdministrador ca = new CommandAdministrador();
				ca.sairSistema(request, response);
			}else if(request.getParameter("cmd").trim().equalsIgnoreCase("consultarAdm")){
				CommandAdministrador ca = new CommandAdministrador();
				ca.consultarAdministrador(request, response);
			}
	}

	
	
}